import axios from 'axios'
import '../plugins/axios'

// baseURL: process.env.baseURL || 'http://localhost:3000/admin/api' || '/admin/api'
   // 'http://localhost:3000/admin/api'  || '/admin/api'
if (process.env.NODE_ENV === 'production') {
    axios.defaults.baseURL =  process.env.baseURL || '/admin/api'
} else {
    axios.defaults.baseURL = 'http://localhost:3000/admin/api'
}

/**
 * 
 * @param {account,password} data 
 * @returns 
 */

export const Login = data => {
    return axios.post('/login', data)
}

/*********************************** 管理员模块 */
/**
 * 创建账号
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getAccountadd = data => {
    return axios.post('/rest/admin_user/register', data)
}
/**
 * 获取账号列表
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getAccountlist = data => {
    return axios.get('/rest/admin_user', data)
}

/**
 * 解禁用户 和 修改用户信息
 * @param id
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getAccountforbid = (id,data) => {
    return axios.put(`/rest/admin_user/${id}`, data)
}

export const getOneaccount = id => {
    return axios.get(`/rest/admin_user/${id}`)
}
/**
 * 删除用户
 * @param id
 * @returns {AxiosPromise}
 */
export const getAccountDelete = id => {
    return axios.delete(`/rest/admin_user/${id}`)
}
/*********************************** 分类模块 */
/**
 * 获取分类列表
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getClasslist = data => {
    return axios.get('/rest/class',data)
}

/**
 * 修改分类
 * @param id
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getClassedit = (id, data) => {
    return axios.put(`/rest/class/${id}`,data)
}

/**
 * 删除分类
 * @param id
 * @returns {AxiosPromise}
 */
export const getClassdelete = id => {
    return axios.delete(`/rest/class/${id}`)
}

/**
 * 查询分类详情
 * @param id
 * @returns {AxiosPromise<any>}
 */
export const getClassdetail = id => {
    return axios.get(`/rest/class/art/${id}`)
}

/**
 * 添加分类
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getClassadd = data => {
    return axios.post('/rest/class', data)
}

/*********************************** 文章模块 */
/**
 * 添加文章
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getArticleadd = data => {
    return axios.post(`/rest/article`,data)
}

/**
 * 获取文章列表
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getArticlelist = data => {
    return axios.get(`/rest/article/art`,data)
}

/**
 * 是否展示文章 和修改文章
 * @param id
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getArticleLook = (id,data) => {
    return axios.put(`/rest/article/art/${id}`,data)
}

/**
 * 删除某篇文章
 * @param id
 * @returns {AxiosPromise}
 */
export const getArticledelete = id => {
    return axios.delete(`/rest/article/${id}`)
}

/**
 * 查询文章详情
 * @param id
 * @returns {AxiosPromise<any>}
 */
export const getArticledetail = id => {
    return axios.get(`/rest/article/art/${id}`)
}

/*********************************** 友情模块 */

/**
 * 添加友链
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getFriendlinkadd = data => {
    return axios.post(`/rest/friend`,data)
}

/**
 * 获取友链
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getFriendlinklist = data => {
    return axios.get('/rest/friend',data)
}

/**
 * 修改友链
 * @param id
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getFrendlinkedit = (id,data) => {
    return axios.put(`/rest/friend/${id}`,data)
}

/**
 * 获取友链详情
 * @param id
 * @returns {AxiosPromise<any>}
 */
export const getFriendlinkdetail = id => {
    return axios.get(`/rest/friend/${id}`)
}

/**
 * 删除友链
 * @param id
 * @returns {AxiosPromise}
 */
export const getFriendlinkdelete = id => {
    return axios.delete(`/rest/friend/${id}`)
}

/***************************** 留言模块 */

/**
 * 获取留言列表
 * @returns {AxiosPromise<any>}
 */
export const getCommentlist = () => {
    return axios.get(`/rest/comment/comment`)
}

/**
 * 删除留言
 * @param id
 * @returns {AxiosPromise}
 */
export const getCommentdelete = id => {
    return axios.delete(`/rest/comment/${id}`)
}

/**
 * 回复留言
 * @param models
 * @returns {AxiosPromise<any>}
 */
export  const getCommentup = models => {
    return axios.post(`/rest/comment`, models)
}

/**
 * 添加背景音乐
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getMusicadd = data => {
    return axios.post(`/rest/music`,data)
}

/**
 * 获取列表
 * @returns {AxiosPromise<any>}
 */
export const getMusiclist = () => {
    return axios.get('/rest/music')
}

/**
 * 修改背景音乐
 * @param id
 * @param data
 * @returns {AxiosPromise<any>}
 */
export const getMusicedit = (id,data) => {
    return axios.put(`/rest/music/${id}`,data)
}

/**
 * 获取音乐详情
 * @param id
 * @returns {AxiosPromise<any>}
 */
export const getMusicdetail = id => {
    return axios.get(`/rest/music/${id}`)
}

export const getMusicdelete = id => {
    return axios.delete(`/rest/music/${id}`)
}
